package com.user.model;
//数据接口
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class R<T> implements Serializable {
    //代码状态
    private int code;
    //返回消息
    private String msg;
    //是否请求成功
    private boolean status;
    //回写数据
    private T data;
    //数据条数
    private long total;

    R(int code, String msg){
        this.code = code;
        this.msg = msg;
    }

    R(T data, long total){
        this.data = data;
        this.total = total;
    }

    R(int code, String msg, T data, long total){
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.total = total;
    }

    R(int code, boolean status, T data, long total){
        this.code = code;
        this.status = status;
        this.data = data;
        this.total = total;
    }

    public static R ok(String msg){
        return new R(200,msg,true,null,0);
    }

    public static<T> R ok(T data, long total){
        return new R(200,true,data,total);
    }

    public static R ok(String msg, Object data, long total){
       return new R(200,msg,true,data,total);
    }

    public static R error(int code, String msg){
        return new R(code,msg,false,null,0);
    }

    public static R error(int code, String msg, Object data, long total){
        return new R(code,msg,false,data,total);
    }

}
